import { createInputBox } from '../components/inputBox.js';
import { createReminderList } from '../components/reminderList.js';

export async function initHomePage() {
    const app = document.getElementById('app');

    const inputBox = createInputBox(async (text) => {
        try {
            await fetch('/api/reminders', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ text })
            });
            const reminderList = await createReminderList();
            app.replaceChild(reminderList, app.children[1]);
        } catch (error) {
            console.error('添加提醒失败:', error);
        }
    });

    const reminderList = await createReminderList();

    app.appendChild(inputBox);
    app.appendChild(reminderList);
}
    